package morning.cat.number;

import org.junit.Test;

/**
 * @describe: 类描述信息
 * @author: morningcat.zhang
 * @date: 2019/4/15 3:52 PM
 */
public class NumberTest {
    @Test
    public void test3() throws Exception {
        float a = 0.9f - 0.8f;
        float b = 0.8f - 0.7f;
        float c = 0.7f - 0.6f;
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);


    }

    @Test
    public void test4() {
        double x1 = 1.0 - 0.9;
        double x9 = 0.9 - 0.8;
        double x8 = 0.8 - 0.7;
        double x7 = 0.7 - 0.6;
        double x6 = 0.6 - 0.5;
        double x5 = 0.5 - 0.4;
        double x4 = 0.4 - 0.3;
        double x3 = 0.3 - 0.2;
        double x2 = 0.2 - 0.1;
        System.out.println(x9);
        System.out.println(x8);
        System.out.println(x7);
        System.out.println(x6);
        System.out.println(x5);
        System.out.println(x4);
        System.out.println(x3);
        System.out.println(x2);
        System.out.println(x1);


    }

    @Test
    public void test5() {
        double x9 = 0.9 - 0.8;
        double x8 = 0.8 - 0.7;
        System.out.println(equals(x9, x8, 0.00001));
    }

    private boolean equals(Double num1, Double num2, Double x) {
        if (x == null) {
            x = 0.0;
        }
        if (x < 0) {
            throw new RuntimeException("精度格式不合法，精度为大于等于0的数。");
        }
        if (num1 == null || num2 == null) {
            return false;
        }
        if (Math.abs(num1 - num2) < x) {
            return true;
        }
        return false;
    }

}
